//=============================================================================
// TFGameReplicationInfo
//=============================================================================
class TFGRI extends GameReplicationInfo config;

struct FBIndex
{
    var int Index[10];
};

var() float buildcost[12];

var teaminfo team[2];
var float TeamCredits[2];
var FBIndex BuildingIndex[2];
var int BaseShield[2];
var float TeamEnergy[2];
var float MaxControl[2];
var float Control[2];

replication
{
	// Things the server should send to the client.
	reliable if ( Role == ROLE_Authority )
		MaxControl, Control, BaseShield, TeamCredits, TeamEnergy, BuildingIndex, team;

	reliable if ( Role < ROLE_Authority )
		AddTeamRES, AddTeamSkill;
}

function AddTeamRES(float amount, int t, bool individual)
{
    local int i;
    if(!individual) amount/=team[t].size;
    for(i=0; i<PRIArray.Length; i++)
 {
        if(PRIArray[i].Team == None)
            continue;
	    if(PRIArray[i].Team.TeamIndex==t)
            tfpri(PRIArray[i]).AddRES(amount);
	}
}

function AddTeamSkill(float amount, int t, optional bool noXP)
{
    local int i;

    for(i=0; i<PRIArray.Length; i++)
	{
	    if(PRIArray[i].Team.TeamIndex==t)
            tfpri(PRIArray[i]).AddSkill(amount,0,noXP);
	}
}

simulated function PostNetBeginPlay()
{
	local PlayerReplicationInfo PRI;


	Level.GRI = self;

	if ( VoiceReplicationInfo == None )
		foreach DynamicActors(class'VoiceChatReplicationInfo', VoiceReplicationInfo)
			break;

	ForEach DynamicActors(class'PlayerReplicationInfo',PRI)
	    if(SentinelPlayerReplicationInfo(PRI) == none)
		   AddPRI(PRI);

	if ( Level.NetMode == NM_Client )
		TeamSymbolNotify();
}

/*function DeclareCommander(optional bool red, optional bool blu)
{
    local playerreplicationinfo candidate0, candidate1;
    local int i, v, cv0, cv1;
    local controller p;
    local playercontroller pc;
    local pawn pwn;

    if(!red && !blu)
    {
        red=true;
        blu=true;
    }

    for(i=0; i<PRIArray.Length; i++)
	{
        v=(tfpri(priarray[i]).votes*1000)+rand(500);

        if(red && priarray[i].Team.TeamIndex==0)
        {
            if(v>cv0)
            {
                candidate0=priarray[i];
                cv0=v;
            }

            tfpri(priarray[i]).isCommander=false;
        }


        if(blu && priarray[i].Team.TeamIndex==1)
        {
            if(v>cv1)
            {
                candidate1=priarray[i];
                cv1=v;
            }

            tfpri(priarray[i]).isCommander=false;
        }
    }

    if(red && candidate0!=none)
    {
        tfpri(candidate0).isCommander=true;
        pwn=controller(candidate0.owner).pawn;
        //pwn.Died(none, none, Location);
        pwn.destroy();
        level.game.restartplayer(controller(candidate0.owner));
    }

    if(blu && candidate1!=none)
    {
        tfpri(candidate1).isCommander=true;
        pwn=controller(candidate1.owner).pawn;
        //pwn.Died(none, none, Location);
        pwn.destroy();
        level.game.restartplayer(controller(candidate1.owner));
    }

    for ( P = Level.ControllerList; P!=None; P=P.nextController )
    {
        if(playercontroller(p)!=none)
        {
            pc=playercontroller(p);

            if(red && p.PlayerReplicationInfo.Team.TeamIndex==0)
            {
                if(p.PlayerReplicationInfo==candidate0) pc.ReceiveLocalizedMessage(class'TaskForces.TFVoteMessage3');
                else pc.ReceiveLocalizedMessage(class'TaskForces.TFVoteMessage2',,candidate0);
            }
            else if(blu && p.PlayerReplicationInfo.Team.TeamIndex==1)
            {
                if(p.PlayerReplicationInfo==candidate1) pc.ReceiveLocalizedMessage(class'TaskForces.TFVoteMessage3');
                else pc.ReceiveLocalizedMessage(class'TaskForces.TFVoteMessage2',,candidate1);
            }
        }
    }
}

simulated function Timer()
{
    local controller p;
    local int t;

    super.Timer();

    if(voteCompleted || level.game.bWaitingToStartMatch) return;

    t=tfGame(level.game).votingtime-elapsedtime;

    for ( P = Level.ControllerList; P!=None; P=P.nextController )
    {
        if(playercontroller(p)!=none) playercontroller(p).ReceiveLocalizedMessage(class'TaskForces.TFVoteMessage1',t);
    }

    if(t<=0)
    {
        voteCompleted=true;
        declareCommander();

        for ( P = Level.ControllerList; P!=None; P=P.nextController )
        {
            if ( !p.PlayerReplicationInfo.bOnlySpectator )
            {
                p.Pawn.GotoState('');
                level.game.AddDefaultInventory(p.Pawn);
                tfpri(p.PlayerReplicationInfo).hasvoted=true;
                //tfGame(level.game).restartplayer(p);
            }
        }
    }
}*/

defaultproperties
{
     buildcost(0)=50.000000
     buildcost(1)=200.000000
     buildcost(2)=200.000000
     buildcost(3)=200.000000
     buildcost(4)=300.000000
     buildcost(5)=600.000000
     buildcost(6)=300.000000
     buildcost(11)=300.000000
     TeamCredits(0)=50.000000
     TeamCredits(1)=50.000000
}
